package com.qiang.consumer.service;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

public class UserServiceFailFast extends HystrixCommand<String> {

    private final boolean throwException;

    public UserServiceFailFast (boolean throwException) {
        super(HystrixCommandGroupKey.Factory.asKey("userServiceFailFastGroup"));
        this.throwException = throwException;
    }
    @Override
    protected String run() throws Exception {
        //不做处理，直接抛出一个异常
        if (throwException) {
            throw new RuntimeException("fail from userService fail fast");
        } else {
            return "success";
        }
    }
}
